package class03;

/**
 * 递归求数组中的最大值
 */
public class Code08_GetMax {

    public static int getMax1(int[] arr, int index) {
        if (index == arr.length) {
            return Integer.MIN_VALUE;
        }
        return Math.max(arr[index], getMax1(arr, index + 1));
    }

    public static int getMax2(int[] arr, int L, int R) {
        if (L == R) {
            return arr[L];
        }
        int M = L + ((R - L) >> 1);
        return Math.max(getMax2(arr, L, M), getMax2(arr, M + 1, R));
    }

    public static void main(String[] args) {
        int[] arr = {5, 1, 7, 9, 4, 3};
        System.out.println(getMax1(arr, 0));
        System.out.println(getMax2(arr, 0, arr.length - 1));
    }
}
